package com.yzc.controller;

import com.yzc.model.query.system.AnnouncementReq;
import com.yzc.model.vo.system.AnnouncementVo;
import com.yzc.result.Result;
import com.yzc.service.AnnouncementService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/announcement")
public class SendAnnouncementController {
    @Autowired
    private AnnouncementService announcementService;

    @GetMapping("/loadAnnouncementByUserId")
    public Result<List<AnnouncementVo>> loadAnnouncementByUserId(@RequestParam("id") Integer id) {
        return Result.success(announcementService.loadAnnouncementByUserId(id));
    }

    @GetMapping("/selectAnnouncement")//查询公告（根据id）
    public Result<List<AnnouncementVo>> selectAnnouncement(@RequestParam("content") String content,
                                                               @RequestParam("publisherId") Integer publisherId
    ) {
        return Result.success(announcementService.selectAnnouncement(content, publisherId));
    }

    @PostMapping("/releaseAnnouncement")
    public Result releaseAnnouncement(@RequestBody AnnouncementReq announcementReq) {
        announcementService.releaseAnnouncement(announcementReq);
        return Result.success();
    }

    @PostMapping("/updateAnnouncement")
    public Result updateAnnouncement(@RequestBody AnnouncementVo announcementVo) {
        announcementService.updateAnnouncement(announcementVo);
        return Result.success();
    }

    @DeleteMapping("/deleteAnnouncementById")
    public Result deleteAnnouncementById(@RequestParam("id") Integer id) {
        announcementService.deleteAnnouncementById(id);
        return Result.success();
    }
}
